home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / HELLO.ZIP / os2 / JCDOM.CMD < prev    next >
Encoding:
Text File  |  1996-04-02  |  4.5 KB  |  106 lines

  1. /******************************* REXX *********************************/
  2. /*  REXX External function to calculate a relative day of the month   */
  3. /*  (for example, the second Tuesday of March).  Input is a four      */
  4. /*  character code of the format "rdmm" where "r" = the relative day  */
  5. /*  of the month (1 - 5 for first through fifth), or "L" for the      */
  6. /*  last day of the month (if you specify "5" and there is no fifth   */
  7. /*  day of the month, you will get an error).  "d" is a number from   */
  8. /*  1 through 7 indicating which day of the week (1=Sunday,           */
  9. /*  7=Saturday).  "mm" is the two-digit number of the month           */
  10. /*  (01=January, 12=December).  The result of the function call is    */
  11. /*  extended calendar date of the form "mm/dd/yyyy" where "yyyy" =    */
  12. /*  the current year, "mm" = the month, and "dd" is the day of the    */
  13. /*  month.  Use a function call to "JCCalJul()" to convert this to a  */
  14. /*  standard Julian date.                                             */
  15. /*                                                                    */
  16. /*  Original program written by Jaime A. Cruz, Jr. and released to    */
  17. /*  the public domain.  If you wish to contact the author, you may    */
  18. /*  do so at 72267.1372@compuserve.com, or jcruz@ibm.net.             */
  19. /**********************************************************************/
  20. /*                   Table of days in each month.                     */
  21. /**********************************************************************/
  22. month.0 = 12
  23. month.1 = 31
  24. month.2 = 28
  25. month.3 = 31
  26. month.4 = 30
  27. month.5 = 31
  28. month.6 = 30
  29. month.7 = 31
  30. month.8 = 31
  31. month.9 = 30
  32. month.10 = 31
  33. month.11 = 30
  34. month.12 = 31
  35.  
  36. Parse Upper Arg code, .
  37. /**********************************************************************/
  38. /*  Extract the relative date information, parsing it into            */
  39. /*  variables.  Also extract the current year from the system.        */
  40. /**********************************************************************/
  41. Parse Value code With 1 which 2 ,
  42.                       2 d 3 ,
  43.                       3 mm 5
  44. year = Left(Date('S'), 4)
  45. If JCLepYer(year) Then
  46.    month.2 = 29
  47.  
  48. /**********************************************************************/
  49. /*  Calculate the first day of the month into Julian format, then     */
  50. /*  determine the last day of that month.                             */
  51. /**********************************************************************/
  52. jul_date = JCCalJul(Right(mm, 2, '0') || '/01/' || ,
  53.                     year)
  54. mm = Strip(mm, 'L', '0')
  55. jul_max = jul_date + month.mm - 1
  56.  
  57. /**********************************************************************/
  58. /*  Calculate upon which day of the week the first day of the month   */
  59. /*  falls.                                                            */
  60. /**********************************************************************/
  61. first_day = JCDoW(jul_date)
  62.  
  63. /**********************************************************************/
  64. /*        Calculate the first occurence of our specified day.         */
  65. /**********************************************************************/
  66. delta = d - first_day
  67. If delta < 0 Then
  68.    delta = delta + 7
  69. jul_date = jul_date + delta
  70.  
  71. /**********************************************************************/
  72. /*  Calculate the date of our requested day.  If the user specified   */
  73. /*  the fifth occurence, and it doesn't exist, return an error.       */
  74. /**********************************************************************/
  75. If which \= 'L' Then
  76.    Do
  77.       x = (which - 1) * 7
  78.       jul_date = jul_date + x
  79.       If jul_date > jul_max Then
  80.          jul_date = 'ERROR'
  81.    End
  82. Else
  83.  
  84. /**********************************************************************/
  85. /*  Calculate the last occurence of our requested day (if "L"         */
  86. /*  specified).                                                       */
  87. /**********************************************************************/
  88.    Do
  89.       x = 28
  90.       Do Forever
  91.          If jul_date + x > jul_max Then
  92.             x = x - 7
  93.          Else
  94.             Do
  95.                jul_date = jul_date + x
  96.                Leave
  97.             End
  98.       End
  99.    End
  100. date = JCJulCal(jul_date)
  101.  
  102. /**********************************************************************/
  103. /*       Return to the invoker with the requested information.        */
  104. /**********************************************************************/
  105. Return date
  106.